package com.lzq.springblog.service;

import com.lzq.springblog.dao.BlogInfoMapper;
import com.lzq.springblog.dao.CommentInfoMapper;
import com.lzq.springblog.model.CommentInfo;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Slf4j
@Service
public class CommentService {
    @Autowired
    private CommentInfoMapper commentInfoMapper;

    @Autowired
    private BlogInfoMapper blogInfoMapper;

    public List<CommentInfo> getCommentList(Integer blogId) {
        log.info("开始执行getCommentList方法");
        return commentInfoMapper.queryAllCommentsByBlogId(blogId);
    }

    public Boolean getCanComment(Integer userId, Integer blogId) {
        log.info("开始执行getCanComment方法");
        Integer result = commentInfoMapper.queryUserCommentCountsById(userId,blogId);
        return result<6;
    }

    public Integer addComment(CommentInfo commentInfo) {
        log.info("开始执行addComment方法");
        blogInfoMapper.deleteViewCountsById(commentInfo.getCommentedBlogId());
        return commentInfoMapper.insertComment(commentInfo);
    }
}
